package com.pets.service.Impl;

import com.pets.dao.KnowledgeDisMapper;
import com.pets.dao.KnowledgeMapper;
import com.pets.entity.Knowledge;
import com.pets.entity.KnowledgeDis;
import com.pets.enums.YesNoEnum;
import com.pets.qo.KnowledgeAddQO;
import com.pets.qo.KnowledgeDisAddQO;
import com.pets.service.KnowledgeDisService;
import com.pets.util.AjaxLogicBean;
import com.pets.util.Result;
import com.pets.vo.KnowledgeDisVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class KnowledgeDisServiceImpl implements KnowledgeDisService {
    @Resource
    private KnowledgeDisMapper knowledgeDisDao;
    public AjaxLogicBean<KnowledgeDisVO> getUKnowledgedis(int kId){
        List<KnowledgeDisVO> list=knowledgeDisDao.selectKnowledgeDisByKid(kId);
        AjaxLogicBean<KnowledgeDisVO> alb=new AjaxLogicBean<>();
        alb.setData(list);
        return alb;
    }
    //百科知识的添加操作
    public Result KnowledgeDisAddQO(KnowledgeDisAddQO knowledgeDisAddQO){
        Result result=new Result();
        KnowledgeDis knowledgeDis=new KnowledgeDis();
        knowledgeDis.setKdcontent(knowledgeDisAddQO.getKdContent());
        knowledgeDis.setKdtime(new Date());
        knowledgeDis.setUid(knowledgeDisAddQO.getuId());
        knowledgeDis.setKid(knowledgeDisAddQO.getkId());
        int i=knowledgeDisDao.insert(knowledgeDis);
        if(i >0){
            result.setCode(YesNoEnum.YES.getCode());
            result.setMsg("评论发表成功");
            return result;
        }else {
            result.setCode(YesNoEnum.NO.getCode());
            result.setMsg("评论发表失败");
            return result;
        }

    }
}
